console.log("✅  The latest version of commentsData. js is currently being loaded");
const commentsData = [
    // 原有评论
    {
        id: 1,
        courseId: 1, // Python课程
        userid: "student",
        text: "The explanation of matrix operations in linear algebra is very thorough, and the homework questions are very challenging!"
    },
    {
        id: 2,
        courseId: 2,
        userid: "student",
        text: "Suggest providing more practical examples for the determinant calculation section"
    },
    {
        id: 3,
        courseId: 3, // Web前端课程
        userid: "student",
        text: "The logic of the Newtonian mechanics chapter is clear"
    },
    
    // 新增学生评论（userid固定为"student"）
    {
        id: 4,
        courseId: 4,
        userid: "student",
        text: "IELTS writing skills are too practical for international students!!!"
    },
    {
        id: 5,
        courseId: 5,
        userid: "student",
        text: "The explanation of carbon-14 dating method opened my eyes"
    },
    {
        id: 6,
        courseId: 6,
        userid: "student",
        text: "Can the recursive relationship derivation process be slower?"
    },
    {
        id: 7,
        courseId: 7, // 新增的数据库课程
        userid: "student",
        text: "The gratitude diary exercise really improved my emotional management!"
    },
    {
        id: 8,
        courseId: 8,
        userid: "student",
        text: "The neuroscience basis for the Mozart effect is fantastic!"
    },
    {
        id: 9,
        courseId: 9, // 新增的机器学习课程
        userid: "student",
        text: "The animated demonstration of pointer memory management is so addictive!"
    }
];

async function initCommentsData() {
    console.log('The comment initialization function is called');
    if(!db){
        console.error('Database not initialized');
        return ;
    }
    try{
        const transaction=db.transaction(['comments'],'readwrite');
        const store=transaction.objectStore('comments');
        const countRequest=store.count();
        
        countRequest.onsuccess=function(){
            if(countRequest.result===0){
                commentsData.forEach(comment=>{
                    store.add(comment);
                });
                console.log('Comment data initialization completed, added in total', commentsData.length, 'A comment');
            } else {
                console.log('Comment data already exists (existing)', countRequest.result, 'Skip initialization');
            }
        }
    } catch(error){
        console.error('Failed to initialize comment data:', error);
    }
}

window.initCommentsData=initCommentsData;